Open
Conversation
Fix the following clippy recomendations: the loop variable `i` is only used to index `p` `#[warn(clippy::needless_range_loop)]` on by default for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loopclippyneedless_range_loop main.rs(31, 17): consider using an iterator: `<item>`, `&mut p` manual implementation of an assign operation for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_patternclippyassign_op_pattern main.rs(36, 9): replace it with: `counter += 1` unneeded `return` statement `#[warn(clippy::needless_return)]` on by default for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_returnclippyneedless_return particle.rs(17, 9): remove `return`: `Particle { redundant field names in struct initialization `#[warn(clippy::redundant_field_names)]` on by default for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_namesclippyredundant_field_names particle.rs(18, 13): replace it with: `pos` manual implementation of an assign operation `#[warn(clippy::assign_op_pattern)]` on by default for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_patternclippyassign_op_pattern particle.rs(32, 9): replace it with: `self.pos[0] += self.vel[0]` Signed-off-by: Marc Jones <marcj303@gmail.com> fix clippy Signed-off-by: Marc Jones <marcj303@gmail.com>
Similar to the previous clippy recomendation, use Rust iterator instead of a for loop to remove particles that have reached the end of lifetime. Note that the article mentions that the for loop goes backwards, but that isn't neccesary for two reasons. [1] 1. The partical vector is a FIFO, not a stack. The first particals are the oldest, so it should scan front to back. 2. The order of scanning doesn't matter since it is all done before the screen is redrawn. Since we don't really care about what order, the particals are removed from the vector, we can use vector iterator and simplify the code to retain all particals that are not finished. [1] https://medium.com/codex/nature-of-rust-particles-40cec0a8c25e Signed-off-by: Marc Jones <marcj303@gmail.com>
Move adding particals to the vector into the top of the window.next animation loop. We only need to add particals in one place. Signed-off-by: Marc Jones <marcj303@gmail.com>
Use the constants to set the initial partical location to the center of the width and height. Signed-off-by: Marc Jones <marcj303@gmail.com>
Port to the speedy2d crate. Signed-off-by: Marc Jones <marcj303@gmail.com>
We don't need to clone if we borrow self in the finalize function. Signed-off-by: Marc Jones <marcj303@gmail.com>
Add Keyboard r,g,b feature to change the colors of the particles. Keys other than r,g,b turn the particles black. Add Mouse click to move the particles starting point. Signed-off-by: Marc Jones <marcj303@gmail.com>
Signed-off-by: Marc Jones <marcj303@gmail.com>
The start_pos dimensions were switched. Set x to WIDTH and y to HEIGHT. Signed-off-by: Marc Jones <marcj303@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for the great article on medium. I'm learning Rust and this was a great little exercise. This pull request has 4 commits. It fixes issues noted by clippy and refactors some code to simplify and de-duplicate the logic. Please feel free to review and comment on the merit of each commit. I am happy to split this up if you would like separate pull-requests.